import {
  validateDeviceId,
  validateAddress,
  validateNoRequiredInt,
  validateIP
} from "@/utils/rules"
const validateFunc = (rule, value, callback) => {
  // console.log(rule);
  if (value.length === 0) {
    callback(new Error("至少选择一个功能"))
  } else {
    callback()
  }
}
export const formMixin = {
  data() {
    return {
      rulesAddForm: {
        companyId: [
          {
            required: true,
            message: "请选择所属客户"
          }
        ],
        groupId: [
          {
            required: true,
            message: "请选择所属区域"
          }
        ],
        deviceNo: [
          {
            required: true,
            validator: validateDeviceId("设备ID", "设备ID只能输入数字"),
            trigger: "blur"
          },
          {
            min: 12,
            message: "设备ID不得少于12个字符"
          }
        ],
        type: [
          {
            required: true
          }
        ],
        // collectType: [{
        //   required: true
        // }],
        hubHost: [],
        hubPort: [],
        name: [
          {
            required: true,
            validator: validateAddress(
              "设备名称",
              "设备名称只能输入中文、数字、字母、下划线、中划线"
            ),
            trigger: "blur"
          }
        ],
        alias: [
          {
            required: true,
            validator: validateAddress(
              "设备别名",
              "设备别名只能输入中文、数字、字母、下划线、中划线"
            ),
            trigger: "blur"
          }
        ],
        location: [
          {
            required: true,
            validator: validateAddress(
              "设备位置",
              "设备位置只能输入中文、数字、字母、下划线、中划线"
            ),
            trigger: "blur"
          }
        ],
        rate: [
          {
            required: true,
            validator: validateDeviceId("采集频率", "采集频率只能输入正整数"),
            trigger: "blur"
          }
        ],
        ct: [
          {
            required: true,
            validator: validateDeviceId("CT值", "CT值只能输入正整数"),
            trigger: "blur"
          }
        ],
        pt: [
          {
            required: true,
            validator: validateDeviceId("PT值", "PT值只能输入正整数"),
            trigger: "blur"
          }
        ],
        lct: [
          {
            required: true,
            validator: validateDeviceId("LCT值", "LCT值只能输入正整数"),
            trigger: "blur"
          }
        ],
        disconState: [
          {
            required: true
          }
        ],

        enable: [
          {
            required: true
          }
        ],

        // 设备厂商
        vendorId: [
          {
            required: true,
            message: "请选择设备生产厂商"
          }
        ],

        // 设备型号
        modelId: [
          {
            required: true,
            message: "请选择设备型号"
          }
        ],

        // 通道地址
        channelIp: [
          {
            validator: validateIP("通道地址", "通道地址只能输入ip地址"),
            trigger: "blur"
          }
        ],
        heatDirectStream: [
          {
            required: true,
            // validator: validateIP('热成像流', '热成像流地址只能输入ip地址'),
            trigger: "blur"
          }
        ],

        videoDirectStream: [
          {
            required: true,
            // validator: validateIP('视频流地址', '视频流地址只能输入ip地址'),
            trigger: "blur"
          }
        ],
        heatNvrStream: [
          {
            required: true,
            // validator: validateIP('热成像NVR流地址', '热成像NVR流地址只能输入ip地址'),
            trigger: "blur"
          }
        ],

        videoNvrStream: [
          {
            required: true,
            // validator: validateIP('视频NVR流地址', '视频NVR流地址只能输入ip地址'),
            trigger: "blur"
          }
        ],

        // HTTP端口
        httpPort: [
          {
            // required: true,
            validator: validateNoRequiredInt(
              "请输入HTTP端口",
              "HTTP端口只能输入正整数"
            ),
            trigger: "blur"
          }
        ],

        // RTSP端口
        rtspPort: [
          {
            // required: true,
            validator: validateNoRequiredInt(
              "请输入RTSP端口",
              "RTSP端口只能输入正整数"
            ),
            trigger: "blur"
          }
        ],

        // 通讯协议
        protocolId: [
          {
            required: true,
            message: "请选择通讯协议"
          }
        ],

        // 所属录像机
        nvrId: [
          {
            required: true,
            message: "请选择所属录像机"
          }
        ],

        networkType: [
          {
            required: true,
            message: "请选择网络类型"
            // trigger: "change"
          }
        ],
        platform: [
          {
            trigger: "change",
            type: "number",
            required: true,
            message: "请选择网络类型"
          }
        ],
        havPTZ: [
          {
            required: true,
            message: "是否为云台设备"
            // trigger: "change"
          }
        ],
        havNVR: [
          {
            required: true,
            message: "是否有录像机"
          }
        ],

        // 功能设置
        func: [
          {
            required: true,
            // message: "至少启用一个功能",
            validator: validateFunc,
            trigger: "change"
          }
        ]
      }
    }
  }
}

export const addForm = {
  companyId: "",
  groupId: "",
  name: "",
  alias: "",
  location: "",
  deviceNo: "",
  type: 1,
  func: [],
  // collectType: '',

  vendorId: "",
  modelId: "",
  nvrId: "",
  channelIp: "",
  httpPort: "",
  rtspPort: "",
  protocolId: "",
  enable: false,
  hubHost: "",
  hubPort: "",
  rate: 15,
  ct: null,
  lct: null,
  pt: null,
  havPTZ: false,
  havNVR: false,
  networkType: 1,
  disconState: false,
  heatDirectStream: "",
  videoDirectStream: "",
  heatNvrStream: "",
  videoNvrStream: "",
  platform: 1,
  cameraVideoCode: "",
  cameraThermalCode: "",
  nvrVideoCode: "",
  nvrThermalCode: "",
  directVideoCode: "",
  directThermalCode: ""
}
